<?php if ( ! defined('IN_APF')) exit('No direct script access allowed');

/**
 * 数据存取接口
 *
 * @author heshun
 */
class DataAccess {

    private static $verbose = 0;

    /**
     * 返回数据库配置信息
     * @param <String> $fullTableName
     * @return <String>
     */
    static public function table($fullTableName)
    {
        list($project, $modName, $tableName) = explode('.', $fullTableName);
        if (isset($GLOBALS['MODULE_SETTING'][$modId]['db'][$tableName]))
        {
            $dbInfo = $GLOBALS['MODULE_SETTING'][$modId]['db_host'][$tableName]:
        }
        else
        {
            $dbInfo = '*';
        }

        if (empty($GLOBALS['PROJECT_CONFIG']['db_host'][$dbInfo]))
        {
            throw new APF_Exception("pls config the database server!");
        }

        //return DB::getInstance($GLOBALS['PROJECT_CONFIG']['db_host'][$dbInfo]);
        return $GLOBALS['PROJECT_CONFIG']['db_host'][$dbInfo];
    }

    static public function select($fullTableName)
    {
        require_module_file('framework.da', '/Select.class.php');

        return new Select(self::table($fullTableName));
    }

    static public function update($fullTableName)
    {
        require_module_file('framework.da', '/Update.class.php');

        return new Update(self::table($fullTableName));
    }

    static public function insert($fullTableName)
    {
        require_module_file('framework.da', '/Insert.class.php');

        return new Insert(self::table($fullTableName));
    }

    static public function delete($fullTableName)
    {
        require_module_file('framework.da', '/Delete.class.php');

        return new Delete(self::table($fullTableName));
    }

}

?>